<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>表格全选</title>
    <style>
        table {
            border: 1px solid;
            width: 500px;
            margin-left: 30%;
        }

        td, th {
            text-align: center;
            border: 1px solid;
        }

        div {
            margin-top: 10px;
            margin-left: 30%;
        }

        .btn_focus {
            background-color: pink;
        }

        .btn_blur {
            background-color: white;
        }
    </style>


    <script>
        window.onload = function () {
            //全选
            let allcd = document.getElementById("selectAll");
            allcd.onclick = function () {
                let input_btn = document.getElementsByTagName("input");
                for (let i = 0; i < input_btn.length; i++) {
                    input_btn[i].checked = true;
                }
            }

            //全不选
            let unSelectAll = document.getElementById("unSelectAll");
            unSelectAll.onclick = function () {
                let input_btn = document.getElementsByTagName("input");
                for (let i = 0; i < input_btn.length; i++) {
                    input_btn[i].checked = false;
                }
            }

            //反选
            let selectRev = document.getElementById("selectRev");
            selectRev.onclick = function () {
                let input_btn = document.getElementsByTagName("input");
                for (let i = 0; i < input_btn.length; i++) {
                    input_btn[i].checked = !input_btn[i].checked;
                }
            }

            //frist选择
            let frist = document.getElementById("frist");
            let input_cd = document.getElementsByTagName("input");
            frist.onclick = function () {

                for (let i = 0; i < input_cd.length; i++) {
                    input_cd[i].checked = frist.checked;
                }
            }


            //显示背景颜色
            let tr = document.getElementsByTagName("tr");
            for (let i = 0; i < tr.length; i++) {
                tr[i].onmouseover = function () {
                    this.className = "btn_focus";
                }
                tr[i].onmouseout = function () {
                    this.className = "btn_blur";
                }

            }
        }
    </script>
</head>
<body>

<table>
    <caption>学生信息表</caption>
    <tr>
        <th><input type="checkbox" id="frist"></th>
        <th>编号</th>
        <th>姓名</th>
        <th>性别</th>
        <th>操作</th>
    </tr>

    <tr>
        <td><input type="checkbox"></td>
        <td>1</td>
        <td>令狐冲</td>
        <td>男</td>
        <td><a href="javascript:void(0);">删除</a></td>
    </tr>

    <tr>
        <td><input type="checkbox"></td>
        <td>2</td>
        <td>任我行</td>
        <td>男</td>
        <td><a href="javascript:void(0);">删除</a></td>
    </tr>

    <tr>
        <td><input type="checkbox"></td>
        <td>3</td>
        <td>岳不群</td>
        <td>?</td>
        <td><a href="javascript:void(0);">删除</a></td>
    </tr>

</table>
<div>
    <input type="button" id="selectAll" value="全选">
    <input type="button" id="unSelectAll" value="全不选">
    <input type="button" id="selectRev" value="反选">
</div>
</body>
</html>